/**
 * 
 */
package fr.gfi.agraf.vue.action.gerer.excel;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.util.CollectionUtils;

import fr.gfi.agraf.exception.AgrafException;
import fr.gfi.agraf.service.IPerimetreService;
import fr.gfi.agraf.utils.PropertiesUtils;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;
import fr.gfi.agraf.vue.bean.LigneExcelImportBean;
import fr.gfi.agraf.vue.bean.PerimetreDTO;

/**
 * @author Fw
 * 
 */
public class VoirImportExcelAction extends AbstractApplicationSupportAction {

	/**
	 * Généré par Java
	 */
	private static final long serialVersionUID = -8947061884805405751L;

	private static final String PERIMETRE_SERVICE = "PerimetreService";

	private static final String POPUP_AIDE_EXTENSION = "popup.aide.importer.excel.extension";
	private static final String POPUP_AIDE_TEMPLATE = "popup.aide.importer.excel.template";
	private static final String POPUP_AIDE_TEMPLATE_BIS = "popup.aide.importer.excel.template.bis";

	private boolean isResult;
	private List<LigneExcelImportBean> listeLignesAjoutees;

	private List<PerimetreDTO> listePerimetres;

	private List<String> listeInfoPage;

	/**
	 * Logger
	 */
	private final static Logger LOGGER = Logger.getLogger(VoirImportExcelAction.class);

	@SuppressWarnings("unchecked")
	@Override
	public String executeAction() throws Exception {

		listeLignesAjoutees = (List<LigneExcelImportBean>) getServletRequest().getAttribute(
				ImportExcelAction.LISTE_IMPORT_TO_VALIDE);

		if (!CollectionUtils.isEmpty(listeLignesAjoutees)) {
			isResult = true;
		}

		final IPerimetreService perimetreService = (IPerimetreService) SpringFactory.getApplicationContext()
				.getBean(PERIMETRE_SERVICE);
		try {
			// fait appel au service perimetre
			listePerimetres = perimetreService.getListePerimetre();
		} catch (final AgrafException ae) {
			// Recupére le message
			final String message = PropertiesUtils.getProperty(ae.getKey());
			// Ajoute action message
			addActionMessage(message);
			LOGGER.error(message, ae);
			return ERROR;
		}

		listeInfoPage = new ArrayList<String>();
		listeInfoPage.add(PropertiesUtils.getProperty(POPUP_AIDE_EXTENSION));
		listeInfoPage.add(PropertiesUtils.getProperty(POPUP_AIDE_TEMPLATE));
		listeInfoPage.add(PropertiesUtils.getProperty(POPUP_AIDE_TEMPLATE_BIS));

		return SUCCESS;
	}

	/**
	 * @return the isResult
	 */
	public boolean isResult() {
		return isResult;
	}

	/**
	 * @return the listeLignesAjoutees
	 */
	public List<LigneExcelImportBean> getListeLignesAjoutees() {
		return listeLignesAjoutees;
	}

	/**
	 * @return the listePerimetres
	 */
	public List<PerimetreDTO> getListePerimetres() {
		return listePerimetres;
	}

	/**
	 * @return the listeInfoPage
	 */
	public List<String> getListeInfoPage() {
		return listeInfoPage;
	}

}
